package com.espoir.shp.read01;

import java.util.ArrayList;
import java.util.List;

public class App2 {
    public static void main(String[] args) {
        test();
    }

    private static void test() {
        //此处传值既可以是一个目录也可以是一个以.shp结尾的文件，如果是目录的话，会遍历读取所有的以.shp结尾的文件
        String filePath = "D:\\resource\\gis\\sjdata\\sj.shp";
        ShapeReader shapeReader = new ShapeReader();
        ArrayList<ShapeModel> list = shapeReader.readShapeFile(filePath);
        list.forEach((item)->{
            System.out.println("item.getGeoStr() = " + item.getGeoStr());
        });
    }

    public static List<ShapeModel> readShp(String filePath) {

        //此处传值既可以是一个目录也可以是一个以.shp结尾的文件，如果是目录的话，会遍历读取所有的以.shp结尾的文件
//        String filePath = "D:\\test\\test_db_shp.shp";
        ShapeReader shapeReader = new ShapeReader();
        ArrayList<ShapeModel> list = shapeReader.readShapeFile(filePath);
        //ArrayList<Point> pointList = new ArrayList<>();

        //list.forEach((item)->{
        //    String geoStr = item.getGeoStr();
        //    String geo = geoStr.substring(geoStr.lastIndexOf("(") + 1, geoStr.indexOf(")"));
        //    String[] pointStr = geo.split(" ");
        //    System.out.println("pointStr = " + Arrays.toString(pointStr));
        //    Double x = Double.parseDouble(pointStr[0]);
        //    Double y = Double.parseDouble(pointStr[1]);
        //    Point point = new Point(x, y);
        //    pointList.add(point);
        //});
        return list;
    }

    public static List<CountyShapeModel> readCountyShape(String filePath) {

        //此处传值既可以是一个目录也可以是一个以.shp结尾的文件，如果是目录的话，会遍历读取所有的以.shp结尾的文件
//        String filePath = "D:\\test\\test_db_shp.shp";
        CountyShapeReader shapeReader = new CountyShapeReader();
        ArrayList<CountyShapeModel> list = shapeReader.readShapeFile(filePath);
        //ArrayList<Point> pointList = new ArrayList<>();

        //list.forEach((item)->{
        //    String geoStr = item.getGeoStr();
        //    String geo = geoStr.substring(geoStr.lastIndexOf("(") + 1, geoStr.indexOf(")"));
        //    String[] pointStr = geo.split(" ");
        //    System.out.println("pointStr = " + Arrays.toString(pointStr));
        //    Double x = Double.parseDouble(pointStr[0]);
        //    Double y = Double.parseDouble(pointStr[1]);
        //    Point point = new Point(x, y);
        //    pointList.add(point);
        //});
        return list;
    }

    public static List<TownshipShapeModel> readTownshipShape(String filePath) {

        //此处传值既可以是一个目录也可以是一个以.shp结尾的文件，如果是目录的话，会遍历读取所有的以.shp结尾的文件
//        String filePath = "D:\\test\\test_db_shp.shp";
        TownshipShapeReader shapeReader = new TownshipShapeReader();
        ArrayList<TownshipShapeModel> list = shapeReader.readShapeFile(filePath);
        //ArrayList<Point> pointList = new ArrayList<>();

        //list.forEach((item)->{
        //    String geoStr = item.getGeoStr();
        //    String geo = geoStr.substring(geoStr.lastIndexOf("(") + 1, geoStr.indexOf(")"));
        //    String[] pointStr = geo.split(" ");
        //    System.out.println("pointStr = " + Arrays.toString(pointStr));
        //    Double x = Double.parseDouble(pointStr[0]);
        //    Double y = Double.parseDouble(pointStr[1]);
        //    Point point = new Point(x, y);
        //    pointList.add(point);
        //});
        return list;
    }

    public static List<CommonShapeModel> readCommonShape(String filePath) {

        //此处传值既可以是一个目录也可以是一个以.shp结尾的文件，如果是目录的话，会遍历读取所有的以.shp结尾的文件
//        String filePath = "D:\\test\\test_db_shp.shp";
        CommonShapeReader shapeReader = new CommonShapeReader();
        ArrayList<CommonShapeModel> list = shapeReader.readShapeFile(filePath);
        //ArrayList<Point> pointList = new ArrayList<>();

        //list.forEach((item)->{
        //    String geoStr = item.getGeoStr();
        //    String geo = geoStr.substring(geoStr.lastIndexOf("(") + 1, geoStr.indexOf(")"));
        //    String[] pointStr = geo.split(" ");
        //    System.out.println("pointStr = " + Arrays.toString(pointStr));
        //    Double x = Double.parseDouble(pointStr[0]);
        //    Double y = Double.parseDouble(pointStr[1]);
        //    Point point = new Point(x, y);
        //    pointList.add(point);
        //});
        return list;
    }

    public static void readShp2(String filePath) {

        //此处传值既可以是一个目录也可以是一个以.shp结尾的文件，如果是目录的话，会遍历读取所有的以.shp结尾的文件
//        String filePath = "D:\\test\\test_db_shp.shp";
        ShapeReader shapeReader = new ShapeReader();
        ArrayList<ShapeModel> list = shapeReader.readShapeFile(filePath);
        int size = list.size();

//        System.out.println("size = " + size);
        System.out.println("list = " + list);
        list.forEach((item)->{
            System.out.println("item = " + item.getGeoStr());
        });
    }
}
